#!/usr/bin/env bash
set -x

base_dir="$(cd `dirname $0`; pwd)"
image_registry='registry.cn-hangzhou.aliyuncs.com/xxx'
list_file="${base_dir}/image.list"

clear

docker images --format '{{.Repository}}:{{.Tag}}' > ${list_file}

while read line
do
  image_name="$(awk -F '/' '{print $NF}' <<< ${line})"
  docker tag ${line} ${image_registry}/${image_name}
  docker push ${image_registry}/${image_name}
  if [ $? -eq 0 ];then
    printf "push ${image_registry}/${image_name} success\n" | tee -a ${base_dir}/push.log
  else
    printf "push ${image_registry}/${image_name} fail\n" | tee -a ${base_dir}/push.log
  fi
done < ${list_file}
